package com.molin.IOtest.objectStreamTest;

import java.io.*;
import java.util.ArrayList;

public class lianxi {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ArrayList<Student> students=new ArrayList<>();
        students.add(new Student("zhangsan",23));
        students.add(new Student("lisi",25));
        students.add(new Student("zhaoliu",27));

        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\IOtest\\objectStreamTest\\pwd.txt"));
        oos.writeObject(students);
        oos.close();

        //read
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("D:\\IdeaProjects\\BasicCode\\mIdeaTest\\src\\com\\molin\\IOtest\\objectStreamTest\\pwd.txt"));
        ArrayList<Student> str= (ArrayList<Student>) ois.readObject();
        for (Student student : str) {
            System.out.println(student.toString());
        }
        ois.close();

    }
}
